package com.ben.multiple.shard.springjdbc;

import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;

public class CustomKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
    static final AtomicInteger atomicInteger = new AtomicInteger(1);
    static {
        String s = LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss"));
        atomicInteger.set(Integer.parseInt(s));
    }

    @Override
    public Integer generateKey() {
        return atomicInteger.getAndIncrement();
    }

    @Override
    public String getType() {
        return "kgs_book_kgn";
    }
}
